//
//  GCMenuBaguaViewController.m
//  GoldChampion
//
//  Created by Mac on 2018/4/12.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "GCMenuBaguaViewController.h"
#import "GCMenuBaGuaAttentionTableViewCell.h"
#import "GCMenuBaguaTableViewCell.h"
#import "GCOtherHomeViewController.h"
@interface GCMenuBaguaViewController ()
@property(nonatomic, strong) NSMutableArray                     *dataSouce;
@property(nonatomic, strong) STButton                     *iconButton;/**< 头像 */
@end

@implementation GCMenuBaguaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataSouce = [NSMutableArray new];
    for (NSInteger i = 0; i < 30; i ++) {
        [self.dataSouce addObject:@(i)];
    }
    [self configSubView];
 //   self.tableView.separatorEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 60, 60)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:30
                                           backgroundColor:FlatMint
                                           backgroundImage:nil
                                                     image:nil];
    buyButton.right = UIScreenWidth - 20;
    buyButton.top = 100;
   // [self.view addSubview:buyButton];
    __weak typeof(self) weakSelf =  self;
    [buyButton setClicAction:^(UIButton *sender) {
        [weakSelf test];
    }];

    // Do any additional setup after loading the view.
}
- (void)test{
    [self.dataSouce addObject:@(self.dataSouce.count)];
    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:self.dataSouce.count - 1 inSection:0];
    [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
#pragma mark --subView
- (void)configSubView{

    self.tableView.contentInset = UIEdgeInsetsZero;
    self.tableView.frame = CGRectMake(0, 0, UIScreenWidth, [TMUtils tabBarTop] + 49 -[TMUtils navgationBarBootom]);
    
    [self.tableView registerClass:[GCMenuBaguaTableViewCell class] forCellReuseIdentifier:@"likeCell"];
    [self.tableView registerClass:[GCMenuBaGuaAttentionTableViewCell class] forCellReuseIdentifier:@"attentionCell"];
    self.tableView.st_noreslutView = [[STNoresultView alloc] initWithFrame:CGRectMake(0, 100, UIScreenWidth, 400) title:@"暂无八卦" buttonTitle:@"去关注" buttonHandle:^(NSString *titleString) {
        
    }];
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
    }];
   // [self.tableView.mj_header beginRefreshing];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSouce.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row %3 == 0) {
        return [GCMenuBaGuaAttentionTableViewCell cellHeight];
    }
    return [GCMenuBaguaTableViewCell cellHeight];;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row %3 == 0) {
        GCMenuBaGuaAttentionTableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:@"attentionCell"];
        return cell;

    }else{
        GCMenuBaguaTableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:@"likeCell"];
        [cell debugRandromImage];
        return cell;
    }
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.parentViewController.navigationController pushViewController:[GCOtherHomeViewController new] animated:YES];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}


@end
